Today, I’m going to walk you through this R Markdown document to demonstrate its anatomy and functionality, without narrating. Sit back, relax, and take note of the overall process. We’ll discuss subsequently.
#this is a built-in dataset. See details here:
?swiss
swiss <- swiss
This dataframe contains “standardized fertility measure and socio-economic indicators for each of 47 French-speaking provinces of Switzerland at about 1888.”
#First, I'll load my packages.
library(tidyverse)
library(skimr)
# As you see, when I run that code, I receive some messages about those packages, and I don't really feel like seeing those, so I'll change the chunk options to control the output.
#Next, I'll skim the dataframe
skim(swiss)
| Name | swiss |
| Number of rows | 47 |
| Number of columns | 6 |
| _______________________ | |
| Column type frequency: | |
| numeric | 6 |
| ________________________ | |
| Group variables | None |
Variable type: numeric
| skim_variable | n_missing | complete_rate | mean | sd | p0 | p25 | p50 | p75 | p100 | hist |
|---|---|---|---|---|---|---|---|---|---|---|
| Fertility | 0 | 1 | 70.14 | 12.49 | 35.00 | 64.70 | 70.40 | 78.45 | 92.5 | ▂▂▇▇▅ |
| Agriculture | 0 | 1 | 50.66 | 22.71 | 1.20 | 35.90 | 54.10 | 67.65 | 89.7 | ▃▃▆▇▅ |
| Examination | 0 | 1 | 16.49 | 7.98 | 3.00 | 12.00 | 16.00 | 22.00 | 37.0 | ▅▇▆▂▂ |
| Education | 0 | 1 | 10.98 | 9.62 | 1.00 | 6.00 | 8.00 | 12.00 | 53.0 | ▇▃▁▁▁ |
| Catholic | 0 | 1 | 41.14 | 41.70 | 2.15 | 5.20 | 15.14 | 93.12 | 100.0 | ▇▁▁▁▅ |
| Infant.Mortality | 0 | 1 | 19.94 | 2.91 | 10.80 | 18.15 | 20.00 | 21.70 | 26.6 | ▁▂▇▆▂ |
swiss %>%
#remember how those town names weren't really a column? let's fix that right quick.
rownames_to_column(var = "Town") %>%
#now to the viz
ggplot(aes(x = Fertility, y = Infant.Mortality, color = Town)) +
geom_point() +
coord_flip() +
theme(legend.position = "none")
You can hover over the points to see the town name and estimates of fertility and infant mortality.
library(plotly)
#I'm going to save the above visualization as an object
swiss_viz <- swiss %>%
rownames_to_column(var = "Town") %>%
ggplot(aes(x = Fertility, y = Infant.Mortality, color = Town)) +
geom_point() +
coord_flip() +
theme(legend.position = "none")
ggplotly(swiss_viz)
The mean standardized fertility measure among these towns in 1888 was 70.14. I really like what I’ve made, and I think it’s worth rendering so I can share it with my collaborators.